home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-30 | 2.6 KB | 109 lines | [TEXT/CWIE] |
- //
- // This sample demonstrates how to let the user choose an alias file
- // from an "open" dialog. The basic idea is to intercept the pseudo-
- // item 'sfHookOpenAlias' in a CustomGetFile hook function and transform
- // it into 'getOpen'. This causes the dialog to behave as if the user
- // had clicked the open button. Also, we intercept the item number of
- // a check box we have added to the dialog item template in order to
- // allow the user to choose whether to resolve aliases. Finally,
- // when CustomGetFile returns, we call DebugStr to let the user (you,
- // the programmer, not end users -- they'll just see a crash) know
- // what happened.
- //
- // Complaints and kudos to:
- //
- // Pete Gontier
- // Apple Macintosh Developer Technical Support
- // <gurgle@apple.com>
- //
- // Change history
- //
- // 01/25/95 initial version
- // 01/30/95 use AppendDITL instead of copy of System resources
- //
- //
-
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #ifndef __FONTS__
- # include <Fonts.h>
- #endif
-
- #ifndef __DIALOGS__
- # include <Dialogs.h>
- #endif
-
- #ifndef __STANDARDFILE__
- # include <StandardFile.h>
- #endif
-
- #ifndef __RESOURCES__
- # include <Resources.h>
- #endif
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static short gItemIndex_CustomGetCheckBox;
- static const short kResID_CustomGetCheckBox = 128;
-
- static pascal short DlgHookYDProc (short item, DialogRef dRef, void *)
- {
- if (item == sfHookFirstCall)
- {
- Handle checkBoxDitlH = GetResource ('DITL',kResID_CustomGetCheckBox);
- if (!ResError ( ) && checkBoxDitlH)
- {
- DetachResource (checkBoxDitlH);
- if (ResError ( ))
- ReleaseResource (checkBoxDitlH);
- else
- {
- gItemIndex_CustomGetCheckBox = 1 + CountDITL (dRef);
- AppendDITL (dRef,checkBoxDitlH,appendDITLBottom);
- DisposeHandle (checkBoxDitlH);
- }
- }
- }
- else if (item == gItemIndex_CustomGetCheckBox || item == sfHookOpenAlias)
- {
-
- short iType; Rect iRect; Handle iHandle; Boolean iValue;
- GetDialogItem (dRef,gItemIndex_CustomGetCheckBox,&iType,&iHandle,&iRect);
- iValue = GetControlValue ((ControlRef) iHandle);
- if (item != sfHookOpenAlias)
- SetControlValue ((ControlRef) iHandle, !iValue);
- else if (!iValue)
- item = getOpen;
- }
-
- return item;
- }
-
- void main (void)
- {
- if (!InitMac ( ))
- {
- StandardFileReply sfr;
- Point sfWhere = {-1,-1};
- CustomGetFile (nil,-1,nil,&sfr,sfGetDialogID,sfWhere,DlgHookYDProc,nil,nil,nil,nil);
-
- if (sfr.sfGood)
- DebugStr (sfr.sfFile.name);
- else
- DebugStr ("\pAs the world's worst singer would say: 'No reply at all.'");
- }
- }
-